package com.ruoyi.system.service.impl;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.UrgentIndividualManagementEquipment;
import com.ruoyi.system.mapper.UrgentIndividualManagementEquipmentMapper;
import com.ruoyi.system.service.UrgentIndividualManagementEquipmentService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 紧急个体处置设备(UrgentIndividualManagementEquipment)表服务实现类
 *
 * @author makejava
 * @since 2022-11-16 15:22:16
 */
@Service("urgentIndividualManagementEquipmentService")
public class UrgentIndividualManagementEquipmentServiceImpl implements UrgentIndividualManagementEquipmentService {
    @Resource
    private UrgentIndividualManagementEquipmentMapper urgentIndividualManagementEquipmentDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public UrgentIndividualManagementEquipment queryById(Integer id) {
        return this.urgentIndividualManagementEquipmentDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param urgentIndividualManagementEquipment 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<UrgentIndividualManagementEquipment> queryByPage(UrgentIndividualManagementEquipment urgentIndividualManagementEquipment, PageRequest pageRequest) {
        long total = this.urgentIndividualManagementEquipmentDao.count(urgentIndividualManagementEquipment);
        return new PageImpl<>(this.urgentIndividualManagementEquipmentDao.queryAllByLimit(urgentIndividualManagementEquipment, pageRequest), pageRequest, total);
    }

    @Override
    public List<UrgentIndividualManagementEquipment> selectList(UrgentIndividualManagementEquipment urgentIndividualManagementEquipment) {
        return urgentIndividualManagementEquipmentDao.queryAll(urgentIndividualManagementEquipment);
    }

    /**
     * 新增数据
     *
     * @param urgentIndividualManagementEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public UrgentIndividualManagementEquipment insert(UrgentIndividualManagementEquipment urgentIndividualManagementEquipment) {
        this.urgentIndividualManagementEquipmentDao.insert(urgentIndividualManagementEquipment);
        return urgentIndividualManagementEquipment;
    }

    /**
     * 修改数据
     *
     * @param urgentIndividualManagementEquipment 实例对象
     * @return 实例对象
     */
    @Override
    public UrgentIndividualManagementEquipment update(UrgentIndividualManagementEquipment urgentIndividualManagementEquipment) {
        this.urgentIndividualManagementEquipmentDao.update(urgentIndividualManagementEquipment);
        return this.queryById(urgentIndividualManagementEquipment.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.urgentIndividualManagementEquipmentDao.deleteById(id) > 0;
    }

    @Override
    public String importExcel(List<UrgentIndividualManagementEquipment> urgentIndividualManagementEquipments, Boolean isUpdateSupport, String operName) {
        if (StringUtils.isNull(urgentIndividualManagementEquipments) || urgentIndividualManagementEquipments.size() == 0) {
            throw new ServiceException("导入用户数据不能为空！");
        }
        urgentIndividualManagementEquipmentDao.insertBatch(urgentIndividualManagementEquipments);
        return "成功";
    }
}
